package som.simon.reactor;

import reactor.core.Disposable;
import reactor.core.publisher.Flux;

import java.io.IOException;
import java.time.Duration;

public class DisposeMain {

    public static void main(String[] args) throws IOException {

        Flux<String> flux = Flux.range(1, 10)
                .delayElements(Duration.ofSeconds(1))
                .map(ix -> String.format("%06d", ix * 4))
                .log();

        Disposable disposable = flux.subscribe(System.out::println);


        new Thread(() -> {
            try {
                Thread.sleep(6000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            disposable.dispose();
        }).start();

        System.in.read();
    }

}
